import { createApp } from 'vue'
import App from './App.vue'
//导入导航vue_router依赖
import router from './router'
//导入vuex依赖
import store from './store'
// 添加ant css
import "ant-design-vue/dist/antd.css";
// 添加具体的 ant 组件依赖
import {
  Menu,
  Layout,
  Table,
  Button,
  popconfirm,
  Input,
  Modal,
  Form,
  Select,
  Checkbox,
  Radio,
  DatePicker,
  Switch,
} from 'ant-design-vue';

// 用路由的钩子函数添加前端验证逻辑
// 用户名不存在时，不能登录 
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (store.state.token || !to.meta.login) {
      next()
    } else {
      next({
        path: 'login',
        query: { redirect: to.fullPath }
      })
    }
  } else {
    next()
  }
})


createApp(App)
  .use(router)
  .use(store)
  .use(Menu).use(Layout).use(Table).use(Button)
  .use(popconfirm).use(Input).use(Modal).use(Form)
  .use(Select).use(Checkbox).use(Radio).use(DatePicker)
  .use(Switch)
  .mount('#app')
